﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace PlugNT.Cms.ActionLabel
{
    /// <summary>
    /// 产品类别
    /// </summary>
    public class ProductClass
    {
        public static string ViewTxtList(int topcount, string where, int txtNum)
        {
            BLL.ProductClass bll = new BLL.ProductClass();
            StringBuilder strTxt = new StringBuilder();
            DataTable dt = bll.GetList(topcount, where, false, "");
            if (dt.Rows.Count > 0)
            { 
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    strTxt.Append("<div class=\"hang5-1-1-content1\">");
                    strTxt.Append("<div class=\"hang5-1-1-content2\">");
                    strTxt.Append("<font color=\"#b14b09\"><b>" + PlugNT.Common.Utils.CutString(dr["name"].ToString(), 0, txtNum) + "</b></font></div>");
                    string id = dr["cid"].ToString();
                    strTxt.Append(getProductClassByParent(id));
                    strTxt.Append("</div>");
                }

            }
            else
            {
                strTxt.Append("<li>暂无数据显示...</li>");
            }
            return strTxt.ToString();
        }
        /// <summary>
        /// 产品子类
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        private static string getProductClassByParent(string parentId)
        {
            BLL.ProductClass bll = new BLL.ProductClass();
            DataTable dt = bll.GetList(5, "fatherId=" + parentId, false, "");
            StringBuilder sb = new StringBuilder();

            sb.Append("<div class=\"hang5-1-1-content3\">");
            for (int i = 0; i < dt.Rows.Count - 1; i++)
            {
                DataRow dr = dt.Rows[i];
                sb.Append("<a href=\"\">" + PlugNT.Common.Utils.CutString(dr["name"].ToString(), 0, 4) + "</a>&nbsp;");
            }
            sb.Append("</div>");
            if (dt.Rows.Count > 4)
            {
                sb.Append("<div class=\"hang5-1-1-content4\">");
                sb.Append(">>更多");
                sb.Append("</div>");
            }
            return sb.ToString();
        }
    }
}
